package com.ruoyi.cases.service.impl;

import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cases.mapper.JlQuantitativeTypeMapper;
import com.ruoyi.cases.domain.JlQuantitativeType;
import com.ruoyi.cases.service.IJlQuantitativeTypeService;

/**
 * 定额定量Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@Service
public class JlQuantitativeTypeServiceImpl implements IJlQuantitativeTypeService 
{
    @Autowired
    private JlQuantitativeTypeMapper jlQuantitativeTypeMapper;

    /**
     * 查询定额定量
     * 
     * @param id 定额定量主键
     * @return 定额定量
     */
    @Override
    public JlQuantitativeType selectJlQuantitativeTypeById(String id)
    {
        return jlQuantitativeTypeMapper.selectJlQuantitativeTypeById(id);
    }

    /**
     * 查询定额定量列表
     * 
     * @param jlQuantitativeType 定额定量
     * @return 定额定量
     */
    @Override
    public List<JlQuantitativeType> selectJlQuantitativeTypeList(JlQuantitativeType jlQuantitativeType)
    {
        List<JlQuantitativeType> list = jlQuantitativeTypeMapper.selectJlQuantitativeTypeList(jlQuantitativeType);
        for(JlQuantitativeType jlQuantitativeType1:list){
            jlQuantitativeType1.setRatedUnitName(DictUtils.getDictLabel("jl_case_unit",String.valueOf(jlQuantitativeType1.getRatedUnit()))+"/人/天");
            jlQuantitativeType1.setCostUnitName("元/"+DictUtils.getDictLabel("jl_case_unit",String.valueOf(jlQuantitativeType1.getCostUnit())));
        }
        return list;
    }

    /**
     * 新增定额定量
     * 
     * @param jlQuantitativeType 定额定量
     * @return 结果
     */
    @Override
    public int insertJlQuantitativeType(JlQuantitativeType jlQuantitativeType)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        /*采用雪花算法设置数据唯一id*/
        jlQuantitativeType.setId(String.valueOf(IdUtil.getSnowflake().nextId()));
        /*设置用户信息*/
        jlQuantitativeType.setCreateTime(DateUtils.getNowDate());
        jlQuantitativeType.setCreateBy(String.valueOf(loginUser.getUserId()));
        jlQuantitativeType.setUpdateTime(DateUtils.getNowDate());
        jlQuantitativeType.setUpdateBy(String.valueOf(loginUser.getUserId()));
        return jlQuantitativeTypeMapper.insertJlQuantitativeType(jlQuantitativeType);
    }

    /**
     * 修改定额定量
     * 
     * @param jlQuantitativeType 定额定量
     * @return 结果
     */
    @Override
    public int updateJlQuantitativeType(JlQuantitativeType jlQuantitativeType)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        jlQuantitativeType.setUpdateTime(DateUtils.getNowDate());
        jlQuantitativeType.setUpdateBy(String.valueOf(loginUser.getUserId()));
        return jlQuantitativeTypeMapper.updateJlQuantitativeType(jlQuantitativeType);
    }

    /**
     * 批量删除定额定量
     * 
     * @param ids 需要删除的定额定量主键
     * @return 结果
     */
    @Override
    public int deleteJlQuantitativeTypeByIds(String[] ids)
    {
        return jlQuantitativeTypeMapper.deleteJlQuantitativeTypeByIds(ids);
    }

    /**
     * 删除定额定量信息
     * 
     * @param id 定额定量主键
     * @return 结果
     */
    @Override
    public int deleteJlQuantitativeTypeById(String id)
    {
        return jlQuantitativeTypeMapper.deleteJlQuantitativeTypeById(id);
    }
}
